package com.basic.business.labelMapping.controller;


import com.basic.business.labelMapping.domain.TLabelMapping;
import com.basic.business.labelMapping.service.ITLabelMappingService;
import com.basic.common.annotation.FileExport;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.core.page.TableDataInfo;
import com.basic.common.enums.BusinessType;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import com.basic.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * 商品标签映射管理Controller
 *
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/labelMapping")
public class
TLabelMappingController extends BaseController
{
    @Resource
    private ITLabelMappingService tLabelMappingService;

    /**
     * 查询商品标签映射管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:labelMapping:list')")
    @GetMapping("/list")
    public TableDataInfo list(TLabelMapping tLabelMapping)
    {
        startPage();
        List<TLabelMapping> list = tLabelMappingService.getList(tLabelMapping);
        return getDataTable(list);
    }

    /**
     * 导出商品标签映射管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:labelMapping:export')")
    @Log(title = "商品标签映射管理", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "商品标签映射管理.xlsx")
    @PostMapping("/export")
    public String export(TLabelMapping tLabelMapping) throws IOException
    {
        List<TLabelMapping> list = tLabelMappingService.getList(tLabelMapping);
        return EasyExcelUtils.excelExport(TLabelMapping.class,"商品标签映射管理数据", list);
    }

    /**
     * 获取商品标签映射管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:labelMapping:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tLabelMappingService.get(id));
    }

    /**
     * 新增商品标签映射管理
     */
    @PreAuthorize("@ss.hasPermi('business:labelMapping:add')")
    @Log(title = "商品标签映射管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TLabelMapping tLabelMapping)
    {
        return toAjax(tLabelMappingService.insert(tLabelMapping));
    }

    /**
     * 修改商品标签映射管理
     */
    @PreAuthorize("@ss.hasPermi('business:labelMapping:edit')")
    @Log(title = "商品标签映射管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TLabelMapping tLabelMapping)
    {
        return toAjax(tLabelMappingService.update(tLabelMapping));
    }

    /**
     * 删除商品标签映射管理
     */
    @PreAuthorize("@ss.hasPermi('business:labelMapping:remove')")
    @Log(title = "商品标签映射管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tLabelMappingService.deleteByIds(ids));
    }

    /**
     * 导入数据
     */
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws IOException {
        ExcelUtil<TLabelMapping> util = new ExcelUtil<TLabelMapping>(TLabelMapping.class);
        List<TLabelMapping> list = util.importExcel(file.getInputStream());
        tLabelMappingService.importFileData( list);
        return success("文件数据导入成功");
    }
}
